package rpc

import (
	"encoding/json"
	"bytes"
	"io/ioutil"
	"net/http"
	"errors"
)
type BindSignInfo struct {
	WalletId  string  `json:"walletId"`
	ActivationCode string  `json:"activationCode"`
	PeerId string `json:"peerId"`
}

func SetEthHost()(string){
	//return "http://10.103.244.217:7999/"
	return "http://139.220.193.149:7999/"
}

func HttpEthPost( rpc RPCParam ,sendethHost string)(interface{}, error) {
	b, err := json.Marshal(rpc)
	if err != nil {
		return "", err
	}
	body := bytes.NewBuffer([]byte(b))
	res,err := http.Post(sendethHost, "application/json;charset=utf-8", body)
    if err !=nil{
    	return "", err
	}
	result, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		return "", err
	}
	var s RPCResult;
	err = json.Unmarshal(result, &s)
	if s.Error.Code!=0 {
		return "", errors.New(s.Error.Message)
	}
	return s.Result, nil
}